# 读取数据
import pandas as pd
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore')

df=pd.read_csv('train.csv')
print(df.head())
# 将datetime列，切分出年月日时   YYYY-MM-DD HH:mm:ss
df['月']=df['datetime'].apply(lambda x:int(x.split()[0].split('-')[1]))
df['日']=df['datetime'].apply(lambda x:int(x.split()[0].split('-')[2]))
df['时']=df['datetime'].apply(lambda x:int(x.split()[1].split(':')[0]))
# 按照小时，统计用车数量

df.groupby(['时'])['count'].sum().plot(kind='line')
plt.show()
# 最终按照上班高峰，下班高峰，白天低谷，晚上低谷，分成四个小时段
def a(x):
    if x>=0 and x<=6:
        return 0
    elif x>=7 and x<=10:
        return 1
    elif x>=11 and x<=15:
        return 2
    elif x>=16 and x<=20:
        return 3
    else:return 4
df['时间段']=df['时'].apply(a)
print(df.head())

# 将datetime列，切分出年月日时

# 按照小时，统计用车数量，画出折线图

# 最终按照上班高峰，下班高峰，白天低谷，晚上低谷，分成四个小时段

